﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Xna.Framework.Audio;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using System.Windows.Resources;

namespace Studio77.GuessTheWords2.Core
{
    public class SoundManager
    {
        public const int buttonClick = 1;
        public const int buy = 2;
        public const int keyboard = 3;
        public const int right = 4;
        public const int selectchar = 5;
        public const int selectnull = 6;

        private static Dictionary<int, SoundEffect> effects = new Dictionary<int, SoundEffect>();

        /// <summary>
        /// 播放音效
        /// </summary>
        /// <param name="id"></param>
        public static void PlayEffect(int id)
        {
            if (!StageManager.Instance.IsPlaySound)
            {
                return;
            }
            if (effects.ContainsKey(id))
            {
                FrameworkDispatcher.Update();
                effects[id].Play();
            }
        }

        /// <summary>
        /// 预先加载声音文件
        /// </summary>
        /// <param name="SoundFilePath"></param>
        /// <returns></returns>
        public static SoundEffect PreLoadSound(int id, String SoundFilePath)
        {
            SoundEffect Sound = null;
            try
            {
                StreamResourceInfo SoundFileInfo = Application.GetResourceStream(new Uri(SoundFilePath, UriKind.Relative));
                Sound = SoundEffect.FromStream(SoundFileInfo.Stream);
                effects[id] = Sound;
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Couldn't load sound!" + SoundFilePath);
            }
            return Sound;
        }
    }
}
